﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Husb.WinForm.Controls
{
    public class DataGridViewMoneyCell : DataGridViewTextBoxCell
    {
        protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
        {
			//e.Value = ((Decimal)e.Value).ToString("N");
            //    //e.Value = Decimal.Parse(e.Value.ToString()).ToString("f");
            object o = base.GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context);
            string tmp = o as string;
            if (tmp != null && tmp.Length > 3)
            {
                // 如果是3位数就大于3，4位数就大于4，这里取了3位数（当然最常见是4位数）
                if (tmp.LastIndexOf('.') > 0 && tmp.Length - tmp.LastIndexOf('.') > 3)
                {
                    return tmp.Substring(0, tmp.Length - 2);
                }
            }
            return o;
        }
    }
}
